package com.lili.price;

/**
 * @Auther: 李 力
 * @Date: 2024/8/26
 * @Description: 123.买卖股票的最佳时机 III
 * @version: 1.0
 */
public class LeetCode123 {
    public static int maxProfit(int[] prices) {
        int buy1 = Integer.MIN_VALUE;
        int sell1 = 0;

        int buy2 = Integer.MIN_VALUE;
        int sell2 = 0;

        for (int price : prices) {
            buy1 = Math.max(buy1, -price);
            sell1 = Math.max(sell1, buy1 + price);

            buy2 = Math.max(buy2, sell1 - price);
            sell2 = Math.max(sell2, buy2 + price);
        }
        return sell2;
    }
}
